import React from 'react';
import { routerRedux, Route, Switch } from 'dva/router';
import { LocaleProvider, Spin } from 'antd';
import zhCN from 'antd/lib/locale-provider/zh_CN';
import dynamic from 'dva/dynamic';
import { getRouterData } from './common/router';
import Authorized from './utils/Authorized';
import styles from './index.less';

const { ConnectedRouter } = routerRedux;
const { AuthorizedRoute } = Authorized;
dynamic.setDefaultLoadingComponent(() => {
    return <Spin size="large" className={styles.globalSpin} />;
});
/**
 *@fileName: router.js
 *author: 陈国盼
 *time: 2018/7/5 0005
 *disc:
 *
 *	admin       超级管理员
 *  gly         普通管理员
 *  jdy         接单员
 *  cw          财务
 *  jxs         经销商
 *  syd         事业部
 *
* */
function RouterConfig({ history, app }) {
    const routerData = getRouterData(app);
    const UserLayout = routerData['/user'].component;
    const BasicLayout = routerData['/'].component;
    return (
        <LocaleProvider locale={zhCN}>
            <ConnectedRouter history={history}>
                <Switch>
                    <Route path="/user" component={UserLayout} />
                    <AuthorizedRoute
                        path="/"
                        render={props => <BasicLayout {...props} />}
                        authority={['admin', 'gly', 'jdy', 'cw', 'jxs', 'syd']}
                        redirectPath="/user/login"
                    />
                </Switch>
            </ConnectedRouter>
        </LocaleProvider>
    );
}

export default RouterConfig;
